package restaurant.iterators;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.NoSuchElementException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import restaurant.Table;
import restaurant.Tables;

/**
 * Test case for the OrderedTablesIterator class. Tests to ensure the
 * {@code hasNext} and {@code next} methods work correctly.
 * 
 * @author Odessa
 * 
 */
public class OrderedTablesIteratorTest
{
	Tables tables;
	Iterator it;



	/**
	 * Sets up the test fixture.
	 * 
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		tables = new Tables();
		tables.newTable();
		it = tables.getOrderedTablesIterator();
	}



	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception
	{
	}



	/**
	 * Test method for
	 * {@link restaurant.iterators.iterator.AssignedTablesIterator#hasNext()}. Tests
	 * hasNext() if there are more tables waiting on their order.
	 */
	@Test
	public void testHasNext_Yes()
	{
		tables.orderPlaced(1);
		assertTrue(it.hasNext());
	}



	/**
	 * Test method for
	 * {@link restaurant.iterators.iterator.AssignedTablesIterator#hasNext()}. Tests
	 * hasNext() if there aren't any more tables waiting on their order because
	 * no order was placed.
	 */
	@Test
	public void testHasNext_No()
	{
		assertFalse(it.hasNext());
	}



	/**
	 * Test method for
	 * {@link restaurant.iterators.iterator.AssignedTablesIterator#hasNext()}. Tests
	 * hasNext() if there aren't any more tables waiting on their order because
	 * all orders were delivered.
	 */
	@Test
	public void testHasNext_No2()
	{
		tables.orderPlaced(1);
		tables.orderDelivered(1);
		assertFalse(it.hasNext());
	}



	/**
	 * Test method for {@link restaurant.iterators.iterator.AssignedTablesIterator#next()}
	 * . Tests next() if there are more tables waiting on their order.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_MoreItems()
	{
		Table t = new Table(1);
		t.setOrdered();

		tables.orderPlaced(1);
		assertEquals(t, it.next());
	}



	/**
	 * Test method for {@link restaurant.iterators.iterator.AssignedTablesIterator#next()}
	 * . Tests next() if there aren't any more tables waiting on their order.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_NoMoreItems()
	{
		it.next();
	}

}
